# This code is hosted on http://code.google.com/p/lenthorp/
# Freely available for use in applications, but should NOT be modified
# Email all comments to lenthorpresearch@gmail.com

from warnings import filterwarnings
import MySQLdb
filterwarnings('ignore', category = MySQLdb.Warning)

def ExecuteMySQL(filePath, username='root'):
    db = MySQLdb.connect(user = username)
    c = db.cursor()

    currentLine = ''
    for line in open(filePath):
        if len(line) > 1:
            if not line[0] == '-' and not line[1] == '-':
                currentLine += line
        else:
            currentLine += line
        if not currentLine.find(';') == -1:
            currentLine = currentLine.replace('\n','')
            currentLine = currentLine.replace('\t',' ')
            currentLine = currentLine.replace(';',' ')
            c.execute(currentLine)
            currentLine = ''
    db.close()